<?php
	include_once('header.php');
	if ($_SERVER['REQUEST_METHOD']=='GET' and isset($_GET['url'])) {
		$edit_url_link = $_GET['url'];
		// start 取得要修改的链接的所有信息
		$query="select * from `links` where `url`='".$edit_url_link."'";
		$result_edit_link = $mysql_connection->query($query);
		$edit_link = $result_edit_link->fetch_assoc();
		// end 取得要修改的链接的所有信息
	}
	if ($_SERVER['REQUEST_METHOD']=='POST') {
		$name_link = addslashes($_POST['name_link_text']);
		$url_link = addslashes($_POST['url_link_text']);
		$open_type = addslashes($_POST['open_type_select']);
		$rss_url_link = addslashes($_POST['rss_link_text']);
		$miaoshu_link = addslashes($_POST['miaoshu_link_text']);
		if (isset($_POST['type_submit_hidden']) and $_POST['type_submit_hidden']=='edit_submit') {
			$old_url = $_POST['old_url_hidden'];
			$query_insert_link = "update `links` set `name`='".$name_link."', `url`='".$url_link."', `miaoshu`='".$miaoshu_link."', `rss_url`='".$rss_url_link."', `open_type`='".$open_type."' where `url`='".$old_url."'";
		} else {
			$query_insert_link = "insert into `links` values('".$name_link."','".$url_link."','".$miaoshu_link."','".$rss_url_link."','".$open_type."')";
		}
		$mysql_connection->query($query_insert_link);
	}
?>
<div id="content_b"><form action="<?php echo $_SERVER['PHP_SELF'];?>?message_box=链接已经添加" method="post">
<?php
	if (isset($edit_link)) {
	?>
	<table border="0" width="100%">
		<tr><td>链接名称</td>
		<td><input type="text" class="input_text" name="name_link_text" value="<?php echo $edit_link['name'];?>" /></td></tr>
		<tr><td>链接地址</td>
		<td><input type="text" class="input_text" name="url_link_text" value="<?php echo $edit_link['url'];?>" /></td></tr>
		<tr><td>打开方式</td>
		<?php
			if ($edit_link['open_type']=='_blank') {
			?>
			<td><select name="open_type_select"><option selected value="_blank">_blank - 新窗口或者标签</option>
			<option value="_self">_self - 相同的窗口或者标签</option></select></td></tr>
			<?php
			} else if ($edit_link['open_type']=='_self') {
			?>
			<td><select name="open_type_select"><option value="_blank">_blank - 新窗口或者标签</option>
			<option selected value="_self">_self - 相同的窗口或者标签</option></select></td></tr>
			<?php
			}
		?>
		<tr><td>rss 地址</td>
		<td><input type="text" class="input_text" name="rss_link_text" value="<?php echo $edit_link['rss_url'];?>" /></td></tr>
		<tr><td>描述</td>
		<td><input type="text" class="input_text" name="miaoshu_link_text" value="<?php echo $edit_link['miaoshu'];?>" /></td></tr>
		<input type="hidden" value="edit_submit" name="type_submit_hidden" />
		<input type="hidden" value="<?php echo $_GET['url'];?>" name="old_url_hidden" />
		<tr><td colspan="2" align="right"><input type="submit" value="保存修改" /></td></tr>
	</table>
	<?php
	} else {
	?>
	<table border="0" width="100%">
		<tr><td>链接名称</td>
		<td><input type="text" class="input_text" name="name_link_text" /></td></tr>
		<tr><td>链接地址</td>
		<td><input type="text" class="input_text" name="url_link_text" /></td></tr>
		<tr><td>打开方式</td>
		<td><select name="open_type_select"><option value="_blank">_blank - 新窗口或者标签</option>
		<option value="_self">_self - 相同的窗口或者标签</option></select></td></tr>
		<tr><td>rss 地址</td>
		<td><input type="text" class="input_text" name="rss_link_text" /></td></tr>
		<tr><td>描述</td>
		<td><input type="text" class="input_text" name="miaoshu_link_text" /></td></tr>
		<tr><td colspan="2" align="right"><input type="submit" value="添加链接" /></td></tr>
	</table>
	<?php
	}
?></form></div>
<?php include_once('footer.php');?>
